﻿var selgg = 1;
$(function () {
    $(window).bind("scroll", function () {
        var sTop = $(window).scrollTop();
        var sTop = parseInt(sTop);
        if (sTop >= 100) {
            if (!$("#scrollSearchPro").is(":visible")) {
                try {
                    $("#scrollSearchPro").slideDown();
                } catch (e) {
                    $("#scrollSearchPro").show();
                }
            }
        }
        else {
            if ($("#scrollSearchPro").is(":visible")) {
                try {
                    $("#scrollSearchPro").slideUp();
                } catch (e) {
                    $("#scrollSearchPro").hide();
                }
            }
        }
    });
    for (var i = 0; i < d1.length; i++) {
        $('#bd').append('<a href="/shop/product_dtl?code=' + d1[i].code + '" class="aui-list-product-item"><div class="aui-list-product-item-img"><img src="' + (d1[i].pic == '' ? '/themes/img/default.png' : d1[i].pic) + '"></div><div class="aui-list-product-item-text"><h3>' + d1[i].name + '</h3><div class="aui-list-product-mes-box"><div><span class="aui-list-product-item-price"><em>¥</em>' + d1[i].price_buy + '</span> <span class="aui-list-product-item-del-price">¥' + d1[i].price + '</span></div><div class="aui-comment">' + d1[i].comment_num + '评</div></div></div></a>');
    }
    for (var i = 0; i < gg.length; i++) {
        if (gg[i].name != '' && gg[i].n != 0) {
            $('#ggs').append('<a href="javascript:;"' + (' style="padding: 3px 8px;margin:5px;border:1px solid ' + (selgg == i + 1 ? '#f00;background:#f00;color:#fff;' : '#f60;background:#fff;color:#f60;') + '" onclick="ggsel2(' + (i + 1) + ',this)"') + '>' + gg[i].name + '</a>');
        }
    }
    for (var i = 0; i < gg.length; i++) {
        if (gg[i].n == 1) {
            selgg = i + 1;
            ggsel(i + 1);
            break;
        }
    }
    if (isfavor) {
        $('#favors').html('<span class="aui-f-p-icon"><img src="/themes/img/icon/icon-sc2.png" alt=""></span><span class="aui-f-p-focus-info" style="color:#FF5E53">取消收藏</span>');
    }
});
function favor(code) {
    $.post('/dos_m/product_favor', { code: code, t: isfavor ? 0 : 1 }, function (d) { eval(d); });
}
function ggsel(i) {
    $('#sgg').html(gg[i - 1].name);
    selgg = i;
}
function ggsel2(n, _this) {
    for (var i = 0; i < $('#ggs a').length; i++) {
        $('#ggs a').eq(i).css('color', '#f60');
        $('#ggs a').eq(i).css('background', '#fff');
        $('#ggs a').eq(i).css('border', '1px solid #f60');
    }
    $(_this).css('color', '#fff');
    $(_this).css('background', '#f00');
    $(_this).css('border', '1px solid #f00');
    ggsel(n);
}
function showphone(phone) {
    layer.open({
        content: '<a href="tel:' + phone + '">' + phone + '</a>'
    , btn: '请拨打商户联系电话 点此关闭'
    });
}
function addcart(c) {
    document.getElementById('cancel').click;
    loading();
    $.post('/dos_m/add_cart_upgrade', { code: c, gg: selgg, t: t, dcode: dcode, x: x }, function (d) { eval(d); });
}
function ok() {
    layer.closeAll();
    txttip('加入购物车成功', function () { location.href = '/my/upgrade_shop_dtl?code=' + shopcode + '&x=' + x + '&price_startorder=' + price_startorder; });
}
function ok2() {
    txttip('操作成功', function () { location.href = location.href; });
}